import ajax from '@/utils/ajax'
let _this_;
const getData = () => _this_.curData || _this_.curData;
let usersCheck =(rule, value, callback) => {
    _this_.$ajax.get(_this_.$api.system.user.check,{userName:getData().userName,id:getData().id}).then(result => {
        if(result.bean>0) {
            callback("用户名已存在");
        } else {
            callback();
        }
    }).catch(error => {
        callback("获取用户名异常");
    });
}
export default function (context) {
    _this_ = context;
    return {
        userName: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {min: 3, max: 15, message: '用户名长度在 3 到 15 个字符', trigger: 'blur'},
            {pattern: /^[A-Za-z0-9]+$/, message: '用户名只能是数字或字母', trigger: 'blur'},
            {validator: usersCheck, trigger: 'blur'},
        ],
        nickName: [
            {required: true, message: '请输入昵称', trigger: 'blur'},
            {min: 2, max: 15, message: '昵称长度在 2 到 15 个字符', trigger: 'blur'}
        ],
        deptId: [
            {required: true, message: '请输入部门', trigger: 'blur'},
        ],
        birthday: [
            {required: true, message: '请选择密码有效期', trigger: 'blur'}
        ],
        passwordValid: [
            {required: true, message: '请选择密码有效期', trigger: 'blur'}
        ],
        sex: [
            {required: true, message: '请选择性别', trigger: 'change'}
        ],
        enabled: [
            {required: true, message: '请选择状态', trigger: 'blur'}
        ],
        type: [
            {required: true, message: '请选择用户类型', trigger: 'blur'}
        ],
        phone: [
            {pattern: /^1[3456789]\d{9}$/, message: '目前只支持中国大陆的手机号码', trigger: 'blur'}
        ],
        eamil: [
            {type: 'email', message: '邮箱格式不正确', trigger: 'blur'}
        ]
    }
}
